import { IsNotEmpty, IsNumber, IsString, Length, Matches, ValidateIf } from 'class-validator'

export const phoneRegExp = /^(13[0-9]|14[579]|15[0-3,5-9]|16[567]|17[0135678]|18[0-9]|19[026789])\d{8}$/
export enum VMessage {
    IS_STRING = '$property 应为字符串',
    IS_NOT_EMPTY = '$property 不能为空',
    IS_PHONE = '$property 须为正确的手机号',
    LENGTH = '$property 长度应为$constraint1位',
    LENGTH_MIN = '$property 最少$constraint1位',
    LENGTH_MAX = '$property 最长$constraint1位',
    LENGTH_MIDDLE = '$property 长度应为$constraint1至$constraint2位',
}

export class PhoneDto {
    @Matches(phoneRegExp, { message: '请输入正确的手机号！' })
    phone: string
}
export class UseridDto {
    @IsNotEmpty({ message: '用户ID不能为空！' })
    userid: string
}

export class PageDto {
    @ValidateIf((o) => o.current)
    @IsNumber()
    current: number

    @ValidateIf((o) => o.pageSize)
    @IsNumber()
    pageSize: number
}
export class FlowDto {
    @IsNotEmpty({ message: 'br：分支不能为空！' })
    br: string
    @IsNotEmpty({ message: 'bn：构建号不能为空！' })
    bn: string
    @IsNotEmpty({ message: 'pp：流水线ID不能为空！' })
    pp: string
    @IsNotEmpty({ message: 'rp：仓库不能为空！' })
    rp: string
    @IsNotEmpty({ message: 'pj：项目ID不能为空！' })
    pj: string
}
